﻿using System;
namespace Producers.Kis.Xtee.Riik.Ee.Producer.Kis.Messages {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="kinnitusePohjalAsjaLoomineResponse", Namespace="http://producers.kis.xtee.riik.ee/producer/kis", Target=typeof(KinnitusePohjalAsjaLoomineResponse))]
    public class KinnitusePohjalAsjaLoomineResponseSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IKinnitusePohjalAsjaLoomineResponse clazz;
        
        public KinnitusePohjalAsjaLoomineResponseSerializer(IKinnitusePohjalAsjaLoomineResponse clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.Paring!=null) {
                Writer.WriteStartElement("paring");
                global::Xtee.Core.SerializationMetadata metaParing = this.GetMetaData(clazz.Paring);
                Writer.WriteTypeAttribute(metaParing.TypeQualifiedName.Namespace, metaParing.TypeQualifiedName.Name);
                metaParing.NewSerializer(clazz.Paring).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("keha");
            if (clazz.Keha!=null) {
                global::Xtee.Core.SerializationMetadata metaKeha = this.GetMetaData(clazz.Keha);
                Writer.WriteTypeAttribute(metaKeha.TypeQualifiedName.Namespace, metaKeha.TypeQualifiedName.Name);
                metaKeha.NewSerializer(clazz.Keha).WriteXml(Writer);
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="paring") {
                if ((Reader.IsElementNil() == false)) {
                    global::Xtee.Core.SerializationMetadata metaParing = this.GetMetaData<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IMKMNotification>(Reader, "MKMNotification", "http://producers.kis.xtee.riik.ee/producer/kis");
                    clazz.Paring = metaParing.NewEntity<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IMKMNotification>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("paring");
                        metaParing.NewSerializer(clazz.Paring).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="keha") {
                if ((Reader.IsElementNil() == false)) {
                    global::Xtee.Core.SerializationMetadata metaKeha = this.GetMetaData<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IMKMessageReply>(Reader, "MKMessageReply", "http://producers.kis.xtee.riik.ee/producer/kis");
                    clazz.Keha = metaKeha.NewEntity<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IMKMessageReply>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("keha");
                        metaKeha.NewSerializer(clazz.Keha).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">keha", Reader.LocalName);
            }
        }
    }
}
